function html2ubb(str) {
	str = str.replace(/\r/g,"");
	str = str.replace(/on(load|click|dbclick|mouseover|mousedown|mouseup)="[^"]+"/ig,"");
	str = str.replace(/<script[^>]*?>([\w\W]*?)<\/script>/ig,"");

	str = str.replace(/<a[^>]+href="([^"]+)"[^>]*>(.*?)<\/a>/ig,"[url=$1]$2[/url]");

	str = str.replace(/<font[^>]+color=([^ >]+)[^>]*>(.*?)<\/font>/ig,"[color=$1]$2[/color]");

	str = str.replace(/<img[^>]+src="([^"]+)"[^>]*>/ig,"[img]$1[/img]");
	str = str.replace(/<div style='width:98%;border:1px solid #ccc;padding:3px;'><span class='gray'>(.*)<\/span><\/div>/ig,"[quote]$1[/quote]");
    str = str.replace(/<([\/]?)b>/ig,"[$1b]");
	str = str.replace(/<([\/]?)b>/ig,"[$1b]");
	str = str.replace(/<([\/]?)strong>/ig,"[$1b]");
	str = str.replace(/<([\/]?)u>/ig,"[$1u]");
	str = str.replace(/<([\/]?)i>/ig,"[$1i]");

	str = str.replace(/&nbsp;/g," ");
	str = str.replace(/&amp;/g,"&");
	str = str.replace(/&quot;/g,"\"");
	str = str.replace(/&lt;/g,"<");
	str = str.replace(/&gt;/g,">");

	str = str.replace(/<br>/ig,"\n");
	str = str.replace(/<[^>]*?>/g,"");
	str = str.replace(/\[url=([^\]]+)\]\n(\[img\]\1\[\/img\])\n\[\/url\]/g,"$2");
	str = str.replace(/\n+/g,"\n");
  return str;
}

function trans(){
	var str = "";
	document.getElementById('content').focus();
	var pos = document.selection.createRange();
	rtf.focus();
	rtf.document.body.innerHTML = "";
	rtf.document.execCommand("paste");
	str = rtf.document.body.innerHTML;
	if(str.length == 0) {
		return "";
	}
	pos.text=html2ubb(str);
}

try{
	document.write('<IFRAME id=rtf src="about:blank" width=0 scrolling=no height=0 frameborder="0"></IFRAME><LABEL for=x_paste></LABEL>');
	rtf.document.designMode="On";
}
catch(exp){}

function ctlent(event,id)
{
   var event= event || window.event;
    if( (event.ctrlKey && event.keyCode == 13) || (event.altKey && event.keyCode == 83) && document.getElementById('postsubmit'))
    {
        formobj = document.getElementById(id);
        if(!Validator.Validate(formobj,3)) return false;
        document.getElementById('postsubmit').click();
    }

}
